package genetischeralgorithmus;
import java.util.*;
import java.awt.*;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Dominik
 */
public class Fitness {

LinkedList<Point> places = new <Point>LinkedList();
Double[][] distanceMat;


public void addplace(Point p1){
    places.add(p1);   
}

public LinkedList<Point> getPlaces(){
    return places;
}

public void setupMatrix(){

    //Erzeugt eine Distanzmatrix aus den angegeben Punkten

    distanceMat = new Double[places.size()][places.size()];
    for (int i = 0; i< places.size(); i++){
        for (int j = 0; j< places.size();j++){
            distanceMat [i][j] = Math.sqrt(Math.pow(places.get(i).getX()-places.get(j).getX(),2)+Math.pow(places.get(i).getY()-places.get(j).getY(),2));
        }
    }
}

public void printDistanceMatrix(){
    for (int i=0; i<distanceMat.length;i++){
         System.out.println(Arrays.toString(distanceMat[i]));
    }
   
}

public LinkedList<Double> rate(Population pop1, int coding){

    switch(coding){

        case 1: // Real
            LinkedList<Double> fitnessList = new <Double>LinkedList();

            for (int i = 0; i<pop1.getEntities().length;i++){ //Schleife über alle Entities
                double sumDistance = distanceMat[pop1.getEntities()[i].getPath()[0]-1][pop1.getEntities()[i].getPath()[pop1.getEntities()[i].getPath().length-1]-1] ; // Variable zum Aufaddieren einer Pfadlaenge
                for (int j=0; j< pop1.getEntities()[i].getPath().length-1;j++){ //Lösungsweg einer Entität durchlaufen
                    sumDistance += distanceMat[pop1.getEntities()[i].getPath()[j]-1][pop1.getEntities()[i].getPath()[j+1]-1]; //summiert die entsprechenden werte aus der distanzmatrix auf
                }
                fitnessList.add(sumDistance);
            }

            return fitnessList;




        case 2: //binär

    }

    return null;
}

public void clear(){
    places.clear();
    distanceMat = null;
}
}

